package com.example.blog.schedulerJob;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.blog.domain.UserInformation;
import com.example.blog.service.impl.UserInformationServiceImpl;
import com.example.blog.service.impl.WritingsServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@DisallowConcurrentExecution
@Slf4j
public class UserInfoScheduledCleanupJob implements Job {
    @Resource private Scheduler scheduler;
    @Resource private UserInformationServiceImpl userInformationService;
    @Resource private WritingsServiceImpl writingsService;
    //定时清理注销的用户信息
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        log.info("定时清理任务开始-->");
        try {
            List<UserInformation> info = userInformationService.informationCleanup();
            if(info == null){
                return;
            }
            writingsService.informationCleanup(info);
        }catch (Exception e){
            log.error("定时清理任务-->失败异常");
            throw new JobExecutionException("定时清理任务-->失败异常");
        }
        log.info("定时清理任务结束-->");
    }
}
